package com.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.entity.UseDrug;

@Repository
@Mapper
public interface UseDrugMapper extends BaseMapper<UseDrug> {
    
    @Insert("INSERT INTO usedrug (prescription_detail_id, drug_id, quantity, daily_price) VALUES (#{prescriptionDetailId},#{drugId},#{quantity},(#{drugId}*#{quantity}))")
    void insert(int prescriptionDetailId, int drugId, int quantity);

    @Select("SELECT drug_id FROM Drug WHERE drug_name = #{drugname};")
    int selectByName(String drugname);

    @Select("SELECT SUM(daily_price) FROM usedrug GROUP BY prescription_detail_id")
    int getDailyPriceByPrescriptionId(int prescriptionDetailId);
}
